/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.client;
import ejb.service.IConvertisseurService;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
/**
 *
 * @author TealeaF
 */
public class EjbClient extends JFrame implements ActionListener{
    
    //Class Declarations
    protected JTextField fieldFranc;
    protected JTextField fieldEuro;
    protected JLabel labelFranc;
    protected JLabel labelEuro;
    protected JButton btnConvertir;
    protected JButton btnQuitter;
    /**
     * @param args the command line arguments
     */
    
    public EjbClient(){
        Container container = getContentPane();
	container.setLayout(new FlowLayout());
        this.setSize(300, 150);
        
        labelFranc= new JLabel("Montant en francs :");
        labelEuro= new JLabel("Montant en euros :");
        
        fieldEuro= new JTextField(10);
        fieldFranc= new JTextField(10);
        
        btnConvertir=new JButton("Convertir");
        btnConvertir.addActionListener(this);
        
        btnQuitter=new JButton("Quitter");
        //btnQuitter.addActionListener(new exitApp());

        
        container.add(labelFranc);
        container.add(fieldFranc);
        container.add(labelEuro);
        container.add(fieldEuro);
        container.add(btnConvertir);
        container.add(btnQuitter);
        
        
        
    }
    
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
       InitialContext initialContext;
       try {
           initialContext = new InitialContext();
           IConvertisseurService convertisseur = (IConvertisseurService) initialContext.lookup("192.168.5.76");
           double val = convertisseur.euroVersFrancs(Double.parseDouble(this.fieldFranc.getText()));
           this.fieldEuro.setText(String.valueOf(val));
       } catch (NamingException ex) {
           System.out.println(ex);
       }
   }
            
    public static void main(String[] args) {
        // TODO code application logic here
        
        EjbClient client = new EjbClient();
        client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        client.setVisible(true);
    }
}
